<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>诺诺开票配置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
  <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
  <style>
    .edit{background-color: #ed9c3a;}
    .shenhe{background-color: #429488;}    
    .see{background-color: #7cb717;} 
    .tongbu{background-color: #4c9ef8;color:#fff;}
    .cur{color:#009688;}
    .layui-form-label{width: 120px;}
    .layui-input-block{margin-left: 150px;}
    .userbox,.branchbox{height:200px; overflow-y: auto; z-index: 999; position: absolute; left: 0px; top: 85px; width:400px; background-color:#ffffff; border: 1px solid #ddd;}
    .userbox .list,.branchbox .list{height:38px;line-height: 38px;cursor:pointer; padding-left:10px;}
    .userbox .list:hover,.branchbox .list:hover{background-color:#eeeeee;}
  </style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-fluid">
          <div class="layui-row layui-col-space15">
            <div class="layui-col-md12" style="margin-top:0px">
              <div class="layui-card"> 
                <div class="layui-card-header">诺诺开票配置</div>
                <div class="layui-card-body">
                    
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">授权商户的税号</label>
                    <div class="layui-input-block"><input type="text" placeholder="请输入授权商户的税号" class="layui-input userTax"></div>
                  </div>
                  
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">含税标志</label>
                    <div class="layui-input-block" style="line-height: 38px;">
                        <input type="radio" name="withTaxFlag" value="0" checked>不含税
                        <input type="radio" name="withTaxFlag" value="1">含税
                    </div>
                  </div>
                  
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">税率</label>
                    <div class="layui-input-block"><input type="number" placeholder="请输入授权商户的税号" class="layui-input taxRate">（只支持0.xx）</div>
                  </div>
                  
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">开票人名称</label>
                    <div class="layui-input-block"><input type="text" placeholder="请输入开票人名称" class="layui-input clerk"></div>
                  </div>
                  
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">开票说明</label>
                    <div class="layui-input-block"><input type="text" placeholder="请输入开票说明" class="layui-input remark"></div>
                  </div>
                  
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">开票默认商品名称</label>
                    <div class="layui-input-block"><input type="text" placeholder="请输入开票默认商品名称" class="layui-input goodsName"></div>
                  </div>
                  
                  <div class="layui-row layui-form">
                    <div class="layui-col-md6">
                      <div class="layui-form-item" style="width: 600px">
                        <label class="layui-form-label" style="text-align:center;">默认商品编码</label>
                        <div class="layui-input-block js_bank">
                          <select name="bank" id="bank" lay-filter="bank" lay-search></select>
                          <input type="text" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="搜索商品编码" class="layui-input transfer" style='margin-top:10px;'>
                          <div class="userbox" style='display: none'></div>
                        </div>
                      </div>
                    </div>
                  </div>

                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">access_token</label>
                    <div class="layui-input-block"><input type="text" placeholder="请输入access_token" class="layui-input access_token"></div>
                  </div>
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">app_id</label>
                    <div class="layui-input-block"><input type="text" placeholder="请输入" class="layui-input app_id"></div>
                  </div>
                  <div class="layui-form-item" style="width: 600px">
                    <label class="layui-form-label">app_secret</label>
                    <div class="layui-input-block"><input type="text" placeholder="请输入" class="layui-input app_secret"></div>
                  </div>
                  
                  <div class="layui-form-item">
                    <div class="layui-input-block" style="margin-left:440px"><div class="layui-footer"><button class="layui-btn submit2" style="border-radius:5px">保存</button></div></div>
                  </div>
                  
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <input type="hidden" class="store_id">
  <input type="hidden" class="sort">
  <input type="hidden" class="stu_class_no">

  <input type="hidden" class="stu_order_batch_no">
  <input type="hidden" class="user_id">

  <input type="hidden" class="pay_status">
  <input type="hidden" class="pay_type">
  
  <input type="hidden" class="bankname" value="">
  
  <script src="{{asset('/layuiadmin/layui/layui.js')}}"></script> 
    <script>
    var token = localStorage.getItem("Usertoken");
    var store_id = localStorage.getItem("store_store_id");
    
    var str=location.search;
    var nuonuo_id=str.split('?')[1];
    
    layui.config({
      base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;
      // 未登录,跳转登录页面
      $(document).ready(function(){        
          if(token==null){
              window.location.href="{{url('/user/login')}}";
          }
      })
      
      // 获取配置数据
        $.ajax({
            type: "post",
            url:  location.protocol+'//'+document.domain+"/api/glow/nuonuo_stores",
            async: true,
            dataType: 'json',
            data: {
                token: token,
                nuonuo_id: nuonuo_id,
            },
            success: function (res) {
                if(res.status == 1){
                    $('.userTax').val(res.data.userTax)
                    
                    $('.taxRate').val(res.data.taxRate)
                    $('.clerk').val(res.data.clerk)
                    $('.remark').val(res.data.remark)
                    $('.bankname').val(res.data.goodsCode)
                    $('.goodsName').val(res.data.goodsName)
                    $('.withTaxFlag').val(res.data.withTaxFlag)
                    $('.access_token').val(res.data.access_token)
                    $('.app_id').val(res.data.app_id)
                    $('.app_secret').val(res.data.app_secret)
                    var bankname=res.data.goodsCode;
                    
                    var optionStr = "";
                    for(var i=0;i<res.data_category.length;i++){
                        optionStr += "<option value='" + res.data_category[i].bm + "' "+((bankname==res.data_category[i].bm)?"selected":"")+">" + res.data_category[i].mc + "</option>";
                    }
                    $("#bank").append('<option value="">请选择商品编码</option>'+optionStr);
                    layui.form.render('select');
                }
            },
        });
      
      // 提交信息
        $('.submit2').click(function(){
            $.post("{{url('/api/glow/nuonuo_stores_add')}}", {
                token: token,
                store_id: store_id,
                nuonuo_id: nuonuo_id,
                
                userTax: $('.userTax').val(),
                taxRate: $('.taxRate').val(),
                clerk: $('.clerk').val(),
                remark: $('.remark').val(),
                goodsName: $('.goodsName').val(),
                goodsCode: $('.bankname').val(),
                withTaxFlag: $('input:radio[name="withTaxFlag"]:checked').val(),
                access_token:$('.access_token').val(),
                app_id:$('.app_id').val(),
                app_secret:$('.app_secret').val(),
            }, function(res){
                if(res.status==1){
                    layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 1
                        ,time: 3000
                    });
                }else{
                    layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 2
                        ,time: 3000
                    });
                }
            }, "json");
        });
        
        // 默认商品编码
        $.post("{{url('/api/glow/nuonuo_category')}}", {
            token: token
        }, function(data){
            if(data.status==1){
                var optionStr = "";
                for(var i=0; i<data.data.length; i++){
                    optionStr += "<option value='" + data.data[i].bm + "'>" + data.data[i].mc + "</option>";
                }
                $("#bank").append('<option value="">请选择商品编码</option>'+optionStr);
                layui.form.render('select');
            }
        }, "json");
        
        // 选择商品编码
        form.on('select(bank)', function(data){
            $('.bankname').val(data.value);
        });
        
        // 输入选择商品编码
        $(".transfer").bind("input propertychange", function(event){
          $('.bankname').val($(this).val());
          $.post("{{url('/api/glow/nuonuo_category')}}", {
              token: token,
              tax_code: $(this).val()
          }, function(res){
              var html="";
              for(var i=0;i<res.data.length;i++){
                  html+='<div class="list" data='+res.data[i].bm+'>'+res.data[i].mc+'</div>';
              }
              $(".userbox").show();
              $('.userbox').html('');
              $('.userbox').append(html);
          }, "json");
        });
        
        // 选择商品编码
        $(".userbox").on("click",".list", function(){
            $('.userbox').hide();
            $(".transfer").val('');
            var goodsname=$('.bankname').val();
            var bankname=$(this).attr('data');
            $('.bankname').val( $(this).attr('data') );
            
            $.post("{{url('/api/glow/nuonuo_category')}}", {
                token: token,
                tax_code: goodsname
            }, function(data){
                if(data.status==1){
                    var optionStr = "";
                    for(var i=0;i<data.data.length;i++){
                        optionStr += "<option value='" + data.data[i].bm + "' "+((bankname==data.data[i].bm)?"selected":"")+">" + data.data[i].mc + "</option>";
                    }
                    $("#bank").append('<option value="">请选择商品编码</option>'+optionStr);
                    layui.form.render('select');
                }
            }, "json");
        });
        
        
    });
  </script>
</body>
</html>